package ru.pachkun.home.pages;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;

import ru.pachkun.home.util.DisplayedElementLocatorFactory;
import ru.yandex.qatools.htmlelements.loader.decorator.HtmlElementDecorator;


public class PageManager {
	private WebDriver driver;
	public static final int Time_OUT_PAGE=5;
	public MainInfoPage mainInfoPage;
	public MainPageFrame mainPageFrame;
	public EMSRegistrationPage emsRegistrationPage;
	public MRPORegistrationPage mrpoRegistrationPage;


	public PageManager(WebDriver driver) {
		super();
		this.driver = driver;
		mainInfoPage = initElements(new MainInfoPage(this));
		mainPageFrame = initElements(new MainPageFrame(this));
		emsRegistrationPage = initElements(new EMSRegistrationPage(this));
		mrpoRegistrationPage = initElements(new MRPORegistrationPage(this));
		
	}

	private <T extends Page> T initElements(T page) {
		// PageFactory.initElements(driver, page);
		// PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10),
		// page);
		// 5секунд свой собстевенный таймаут
		PageFactory.initElements(new HtmlElementDecorator(driver), page);
//		PageFactory.initElements(
//				new DisplayedElementLocatorFactory(driver, Time_OUT_PAGE), page);
		return page;
	}

	public WebDriver getDriver() {
		return driver;
	}
}
